﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace FortuneArterial.Site.BusinessLogicLayer.Site
{
    public class SiteHelper
    {
        /// <summary>
        /// 同步主站点的文件到各子站点
        /// </summary>
        /// <remarks>
        /// 将同步：
        /// 1. ~/Views/Shared/
        /// </remarks>
        public static void SynchronousFiles()
        {
            if (HttpContext.Current == null)
            {
                throw new ArgumentNullException("HttpContext.Current", "HttpContext尚未初始化！");
            }
            //获取当前站点Views文件夹绝对路径
            string path = HttpContext.Current.Server.MapPath("~");
            foreach (
                string file in
                    Directory.GetFiles(Path.Combine(path, @"Views\Shared\"), "*.*", SearchOption.AllDirectories))
            {
                foreach (string site in SiteHelper.SUBSITES)
                {
                    string newPath = file.Replace(Path.Combine(path, @"Views\Shared\"),
                        Path.Combine(path, site, @"Views\Shared\"));
                    if (!Directory.Exists(Path.GetDirectoryName(newPath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(newPath));
                    }

                    File.Copy(file, newPath, true);
                }
            }
        }

        public static readonly string[] SUBSITES = new string[] {"API", "Assets", "Laboratory", "Manage", "TFS"};
    }
}
